import React, { Component } from 'react'

import '../assets/style/White_Say/Gbutton.less'
import ReactPayLayer from "react-pay-layer";
export default class Gbutton extends Component {
    constructor(props) {
        super(props);
        this.state = {
            value: '',
            show: false
        };
        // this.ones = this.ones.bind(this)
    }
    pay = (e) => {
        console.log('点击了支付')
        this.setState({
            show: !this.state.show
        })
        console.log(this.state.show)
    }
    onRef = (e) => {
        this.payLayer = e
    }
    //密码输入完成
    inputEnd = (result) => {
      
        if (result === '123456') {
            console.log(this.props)
            this.payLayer.success().then(res => {
                alert('支付成功')
            });
        } else {
            this.payLayer.fail("密码错误");
        }

    }
    handleClose = () => {
        this.pay()
    }
    forgetClickEvent = (e) => {
        alert('忘记密码')
        this.pay()
    }
    render() {
        return (
            <div className="gbutton">{
                this.state.show ? <ReactPayLayer
                    passwordLength={6}
                    successDuration={1000}
                    onRef={this.onRef}
                    handleClose={this.handleClose}
                    forgetClickEvent={this.forgetClickEvent}
                    inputEnd={this.inputEnd}
                /> : <div className="gbutton"><div className="gbutton" onClick={this.pay} > {this.props.title}</div></div> }
            </div>
        )
    }
}
